package com.xtool.livewallpaper.util

import android.content.Context
import android.widget.Toast
import androidx.annotation.StringRes
import com.xtool.livewallpaper.base.ActivityStackManager
import com.xtool.livewallpaper.base.getString
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**
 *
 * @Author: Ricky
 * @Date: 2021/1/20
 */
object ToastUtil {
    fun show(@StringRes res: Int) {
        val text = getString(res)
        if (text.isNotEmpty()) show(text)
    }

    fun show(text: String) {
        ActivityStackManager.currentActivity?.let {
            it.launch(Dispatchers.Main) {
                Toast.makeText(it, text, Toast.LENGTH_SHORT).show()
            }
        }
    }

    fun show(context: Context, text: String) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
    }
}